<template>
  <div class="goods-list">
    <div class="mescroll"  ref="mescroll">
      <tab class="list-tab" 
          custom-bar-width="1.7rem"
          bar-active-color="#172F6D"
          >
        <tab-item selected @on-item-click="onItemClick">全部</tab-item>
        <tab-item @on-item-click="onItemClick">待发货</tab-item>
        <tab-item @on-item-click="onItemClick">已发货</tab-item>
      </tab>
      <div class="list">
        <div class="item" v-for="(item, index) in order_list" :key="index" @click="router({path: './goodsOrderDetails', query:{order_id: item.id}})">
          <img src="@/assets/bolanglang.png" class="bolang" alt="">
          <div class="top">
            <p class="time" v-show="item.create_time">{{item.create_time | formatDate}}</p>
            <p class="status">{{(item.status == "2") ? '已发货' : '待发货'}}</p>
          </div>
          <div class="goods" v-for="(goods, goods_index) in item.goods" :key="goods_index">
            <div class="img">
              <img :src="goods.img">
            </div>
            <div class="title">
              <p class="tip">{{goods.title}}</p>
              <p class="num">数量:{{goods.num}}</p>
            </div>
            <div class="price">¥{{goods.price}}</div>
          </div>
          <p class="all-price">总计金额: ￥{{item.total}}(含运费：¥{{item.freight}})</p>
        </div>
      </div>
      <div class="none" v-show="noDate">
        <img src="@/assets/sousuomendian04.png" alt="">
        <p>暂无相关内容</p>
      </div>
    </div>
  </div>
</template>

<script>

  import { Tab, TabItem } from 'vux'
  import { getOrderList } from "@/api/api";
  import MeScroll from 'mescroll.js'
  import 'mescroll.js/mescroll.min.css'
  import { formatDate } from '@/util/date.js'
  import NoneDiv from "@/components/none"

  export default {
    filters:{
      formatDate(time){
        let date = new Date(time*1000);
        return formatDate(date,'yyyy.MM.dd hh:mm:ss');
      }
    },
    components: {
      Tab,
      TabItem,
      NoneDiv,
    },
    data () {
      return {
        is_check: true,
        mescroll: null, //mescroll实例对象
        status: "",  //发货状态
        order_list: [],  //订单列表
        noDate: false,
      }
    },
    created () {
    },
    //实例化上拉加载
    mounted () {
      this.mescroll = new MeScroll(this.$refs.mescroll, { 
        up: {
          callback: this.upCallback
        }
      })
    },
    methods: {
      router (path) {
        this.$router.push(path)
      },
      onItemClick (index) {
        this.status = index;
        this.mescroll.resetUpScroll()
      },
      upCallback (page) {
        getOrderList(this.status, page.size, page.num).then((res) => {
          if (page.num == 1){
            this.order_list = []
          }
          this.$nextTick(() => {
            this.mescroll.endSuccess(res.data.data);
          })
          this.order_list = this.order_list.concat(res.data.data)
          if(this.order_list.length == 0){
            this.noDate = true;
          }
        }).catch((err) => {
          console.dir(err)
          this.mescroll.endErr()
        })
      },
    }
  }
</script>

<style lang="stylus" scoped>
.goods-list
  width 100%
  height 100vh
  overflow hidden
  background-color #f5f5f5
  .mescroll
    position fixed
    top 0
    bottom 0
    .list-tab
      padding-top 5rem
      margin-bottom 1rem
      .vux-tab-container
        height 5rem
        .vux-tab-item.vux-tab-selected
          font-weight 500
          color #333
        .vux-tab-item
          color #999
          font-size 1.6rem
          font-weight 400
    .item
      background-color #fff
      position relative
      margin-bottom 1rem
      padding 0 1.5rem
      .bolang
        position absolute
        width 100%
        bottom -.3rem
        left 0
      .top
        line-height 4.5rem
        overflow hidden
        border-bottom 1px solid #e6e6e6
        .time
          float left
          color #999
          font-size 1.5rem
        .status
          float right
          color #333
          font-size 1.5rem
      .goods
        display flex
        background-color #fff
        padding 1.5rem 0
        border-bottom 1px solid #e6e6e6
        .img
          min-width 9.4rem
          max-width 9.4rem
          height 7rem
          margin-right 1rem
          display flex
          img
            object-fit cover
        .title
          position relative
          flex 5
          .tip
            font-size 1.5rem
            color #333
            font-weight 500
            width calc(100vw - 17.4rem)
            overflow hidden
            white-space nowrap
            text-overflow ellipsis
          .num
            color #333
            font-size 1.2rem
            line-height 1.6rem
            position absolute
            top 3rem
        .price
          flex 1
          text-align right
          line-height 2.1rem
          font-size 1.5rem
          font-weight 500
          color #A81E27
      .all-price
        line-height 5rem
        height 5rem
        color #333
        font-size 1.5rem
  .none
    img
      position absolute
      top 20.3rem
      width 7.25rem
      left 50%
      margin-left -3.625rem
    p
      color #666
      font-size 1.3rem
      text-align center
      position absolute
      width 100%
      top 32rem
</style>
